package com.xywy.bloodandroid.base;

import android.app.ProgressDialog;
import android.content.Context;
import android.support.v4.app.Fragment;

import com.xywy.bloodandroid.R;
import com.xywy.bloodandroid.util.NetUtil;
import com.xywy.bloodandroid.util.UIUtil;
import com.xywy.bloodandroid.vollery.BaseRequest;
import com.xywy.bloodandroid.vollery.VolleyManager;

/**
 * *****************************************
 * 
 * @Title: BaseFragment.java
 * @Package com.xywy.bloodandroid.base
 * @Description: TODO(Fragment 基类 一些 基本方法 封装)
 * @author smz
 * @date 2014-12-23 上午11:05:38
 * @version V1.0
 ******************************************* 
 */
public class BaseFragment extends Fragment {

	protected ProgressDialog waittingDialog;

	public void waitingDialog(Context context, String message) {
		if (waittingDialog == null)
			waittingDialog = new ProgressDialog(context);
		waittingDialog.setCanceledOnTouchOutside(false);//
		waittingDialog.setMessage(message);
		waittingDialog.show();
	}

	/**
	 * 
	 * 
	 * @param request
	 * @return
	 */
	protected boolean executeRequest(BaseRequest<?> request) {
		if (NetUtil.hasNetwork(getActivity())) {
			waitingDialog(getActivity(),
					getResources().getString(R.string.request));
			VolleyManager.addRequest(request, this);
			return true;
		} else {
			UIUtil.showToast(getActivity(),
					getResources().getString(R.string.not_network));
			UIUtil.DissDialog(getActivity(), waittingDialog);
			return false;
		}
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		VolleyManager.cancelRequest(this);
	}

	@Override
	public void onStop() {
		super.onStop();
		VolleyManager.cancelRequest(this);
	}

}
